﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

using System.Windows.Forms;

namespace UIT_CV_Management
{
    public class DanhGiaTrinhDoNgoaiNgu
    {
        public String MaDanhGiaTrinhDo;
        public Double TrinhDoNghe;
        public Double TrinhDoNoi;
        public Double TrinhDoDoc;
        public Double TrinhDoViet;

        public DanhGiaTrinhDoNgoaiNgu(String _MaDanhGiaTrinhDo)
        {
            QueryResult result = Database.shareDatabase.Query("SELECT * FROM DanhGiaTrinhDoNgoaiNgu " +
                "WHERE MaDanhGiaTrinhDo = '" + _MaDanhGiaTrinhDo + "'");
            if (result.ReturnCode == 200)
            {
                DataRow row = result.Table.Rows[0];
                MaDanhGiaTrinhDo = _MaDanhGiaTrinhDo;
                TrinhDoNghe = Convert.ToDouble(row["MaHoatDongKHKT"]);
                TrinhDoNoi = Convert.ToDouble(row["MaQuaTrinhHoatDongKHKT"]);
                TrinhDoDoc = Convert.ToDouble(row["MaHoiNghiKHKT"]);
                TrinhDoViet = Convert.ToDouble(row["MaKhenThuong"]);
            }
        }

        public DanhGiaTrinhDoNgoaiNgu(Double _TrinhDoNghe, Double _TrinhDoNoi,
            Double _TrinhDoDoc, Double _TrinhDoViet)
        {
            MaDanhGiaTrinhDo = Database.getID("DanhGiaTrinhDoNgoaiNgu", "MaDanhGiaTrinhDo");
            TrinhDoNghe = _TrinhDoNghe;
            TrinhDoDoc = _TrinhDoDoc;
            TrinhDoNoi = _TrinhDoNoi;
            TrinhDoViet = _TrinhDoViet;
        }

        public Boolean Save()
        {
            QueryResult result;
            //Insert
            result = Database.shareDatabase.Query("INSERT INTO DanhGiaTrinhDoNgoaiNgu VALUES(" +
                "'" + MaDanhGiaTrinhDo + "', " +
                "'" + TrinhDoNghe.ToString("00.0") + "', " +
                "'" + TrinhDoDoc.ToString("00.0") + "', " +
                "'" + TrinhDoNoi.ToString("00.0") + "', " +
                "'" + TrinhDoViet.ToString("00.0") + "')");
            if (result.ReturnCode == 200)
                return true;
            else
                return false;

        }
        public Boolean Update()
        {
            QueryResult result;
            if (Database.isDupplicate("DanhGiaTrinhDoNgoaiNgu", "MaDanhGiaTrinhDo", MaDanhGiaTrinhDo))
            {
                //Update
                result = Database.shareDatabase.Query("UPDATE DanhGiaTrinhDoNgoaiNgu SET " +
                    "TrinhDoNghe = '" + TrinhDoNghe.ToString("00.0") + "', " +
                    "TrinhDoDoc = '" + TrinhDoDoc.ToString("00.0") + "', " +
                    "TrinhDoNoi = '" + TrinhDoNoi.ToString("00.0") + "', " +
                    "TrinhDoViet = '" + TrinhDoViet.ToString("00.0") 
                    + "' WHERE MaDanhGiaTrinhDo = '" + MaDanhGiaTrinhDo + "'");
                if (result.ReturnCode == 200)
                    return true;
                else
                    return false;
            }
            return false;
        }
        public Boolean Delete()
        {
            QueryResult result = Database.shareDatabase.Query("DELETE FROM DanhGiaTrinhDoNgoaiNgu " +
                "WHERE MaDanhGiaTrinhDo = '" + MaDanhGiaTrinhDo + "'");
            if (result.ReturnCode == 200)
                return true;
            else
                return false;
        }
    }
}
